home *** CD-ROM | disk | FTP | other *** search
/ Champak 62 / Volume 62 - JOGO DISK .iso / Games / mycutepets.swf / scripts / frame_4 / DoAction.as < prev   
Text File  |  2008-03-17  |  10KB  |  365 lines

  1. function playGameSound()
  2. {
  3.    var _loc1_ = undefined;
  4.    do
  5.    {
  6.       _loc1_ = random(3);
  7.    }
  8.    while(index_sound == _loc1_);
  9.    
  10.    index_sound = _loc1_;
  11.    switch(index_sound)
  12.    {
  13.       case 0:
  14.          sound_MC.playing = "bg1";
  15.          break;
  16.       case 1:
  17.          sound_MC.playing = "bg2";
  18.          break;
  19.       default:
  20.          sound_MC.playing = "bg3";
  21.    }
  22. }
  23. function getTool()
  24. {
  25.    return game._tool;
  26. }
  27. function setTool(t)
  28. {
  29.    cat.onPickTool(t);
  30.    dog.onPickTool(t);
  31.    pony.onPickTool(t);
  32.    game._tool.active = false;
  33.    t.active = true;
  34.    if(t != null)
  35.    {
  36.       Mouse.hide();
  37.       if(t.shakeType == 0)
  38.       {
  39.          onMouseMove = function()
  40.          {
  41.             var _loc2_ = new Array();
  42.             if(cat.enjoying != true && cat.need == t.id && cat.hitTest(_xmouse,_ymouse,true))
  43.             {
  44.                _loc2_.push(cat);
  45.             }
  46.             if(dog.enjoying != true && dog.need == t.id && dog.hitTest(_xmouse,_ymouse,true))
  47.             {
  48.                _loc2_.push(dog);
  49.             }
  50.             if(pony.enjoying != true && pony.need == t.id && pony.hitTest(_xmouse,_ymouse,true))
  51.             {
  52.                _loc2_.push(pony);
  53.             }
  54.             self[cat.mouse].gotoAndStop(1);
  55.             self[dog.mouse].gotoAndStop(1);
  56.             self[pony.mouse].gotoAndStop(1);
  57.             if(_loc2_.length > 0)
  58.             {
  59.                var _loc1_ = _loc2_.length - 1;
  60.                while(_loc1_ >= 0)
  61.                {
  62.                   if(self[_loc2_[_loc1_].mouse]._currentframe != 2)
  63.                   {
  64.                      self[_loc2_[_loc1_].mouse].gotoAndStop(2);
  65.                   }
  66.                   _loc1_ = _loc1_ - 1;
  67.                }
  68.             }
  69.          };
  70.       }
  71.       else if(t.shakeType != 3)
  72.       {
  73.          if(t.shakeType == 1 || t.shakeType == 2)
  74.          {
  75.             var old = [_xmouse,_ymouse][t.shakeType - 1];
  76.             var pets;
  77.             onMouseMove = function()
  78.             {
  79.                pets = new Array();
  80.                if(cat.enjoying != true && cat.need == t.id && cat.hitTest(_xmouse,_ymouse,true))
  81.                {
  82.                   pets.push(cat);
  83.                }
  84.                if(dog.enjoying != true && dog.need == t.id && dog.hitTest(_xmouse,_ymouse,true))
  85.                {
  86.                   pets.push(dog);
  87.                }
  88.                if(pony.enjoying != true && pony.need == t.id && pony.hitTest(_xmouse,_ymouse,true))
  89.                {
  90.                   pets.push(pony);
  91.                }
  92.                if(pets.length > 0)
  93.                {
  94.                   if(t.mov2tg._currentframe != 2)
  95.                   {
  96.                      t.mov2tg.gotoAndStop(2);
  97.                   }
  98.                   var _loc3_ = Math.abs([_xmouse,_ymouse][t.shakeType - 1] - old) / 10;
  99.                   var _loc2_ = pets.length - 1;
  100.                   while(_loc2_ >= 0)
  101.                   {
  102.                      pets[_loc2_].full += _loc3_;
  103.                      pets[_loc2_].inAction = true;
  104.                      delete pets[_loc2_].actionCountrol;
  105.                      if(pets[_loc2_].full >= 100)
  106.                      {
  107.                         pets[_loc2_].goEnjoy(function()
  108.                         {
  109.                            this.full = 100;
  110.                            this.happy += happyIncrement;
  111.                            this.inAction = false;
  112.                            showPoint(this,animal.points[this.need]);
  113.                            point += animal.points[this.need];
  114.                            this.need = 0;
  115.                         }
  116.                         );
  117.                      }
  118.                      _loc2_ = _loc2_ - 1;
  119.                   }
  120.                   old = [_xmouse,_ymouse][t.shakeType - 1];
  121.                }
  122.                else
  123.                {
  124.                   t.mov2tg.gotoAndStop(1);
  125.                }
  126.                dog.actionCountrol();
  127.                cat.actionCountrol();
  128.                pony.actionCountrol();
  129.                if(pets.length > 0)
  130.                {
  131.                   _loc2_ = pets.length - 1;
  132.                   while(_loc2_ >= 0)
  133.                   {
  134.                      if(!pets[_loc2_].enjoying)
  135.                      {
  136.                         pets[_loc2_].actionCountrol = function()
  137.                         {
  138.                            this.inAction = false;
  139.                            delete this.actionCountrol;
  140.                         };
  141.                      }
  142.                      _loc2_ = _loc2_ - 1;
  143.                   }
  144.                }
  145.             };
  146.          }
  147.       }
  148.    }
  149.    else
  150.    {
  151.       dog.actionCountrol();
  152.       cat.actionCountrol();
  153.       pony.actionCountrol();
  154.       if(game._tool.shakeType == 0)
  155.       {
  156.          var pets = new Array();
  157.          if(cat.enjoying != true && cat.need == game._tool.id && cat.hitTest(_xmouse,_ymouse,true))
  158.          {
  159.             pets.push(cat);
  160.          }
  161.          if(dog.enjoying != true && dog.need == game._tool.id && dog.hitTest(_xmouse,_ymouse,true))
  162.          {
  163.             pets.push(dog);
  164.          }
  165.          if(pony.enjoying != true && pony.need == game._tool.id && pony.hitTest(_xmouse,_ymouse,true))
  166.          {
  167.             pets.push(pony);
  168.          }
  169.          if(pets.length > 0)
  170.          {
  171.             var _loc4_ = game._tool;
  172.             var _loc2_ = pets.length - 1;
  173.             while(_loc2_ >= 0)
  174.             {
  175.                pets[_loc2_].inAction = true;
  176.                pets[_loc2_].onFinished = function()
  177.                {
  178.                   this.happy += happyIncrement;
  179.                   this.full = 100;
  180.                   this.inAction = false;
  181.                   showPoint(this,animal.points[this.need]);
  182.                   delete this.onFinished;
  183.                   point += animal.points[this.need];
  184.                   this.need = 0;
  185.                };
  186.                _loc2_ = _loc2_ - 1;
  187.             }
  188.          }
  189.       }
  190.       delete onMouseMove;
  191.       Mouse.show();
  192.    }
  193.    game._tool = t;
  194. }
  195. function showPoint(tag, p)
  196. {
  197.    attachMovie("score_" + p,"point_" + getNextHighestDepth(),getNextHighestDepth(),{_x:pointLocal[tag._name]._x,_y:pointLocal[tag._name]._y});
  198. }
  199. function clearGame()
  200. {
  201.    clearInterval(gameTunerITV);
  202.    clearInterval(gameTimerITV);
  203.    game.tool.active = false;
  204.    game.tool.using = false;
  205.    game.tool = null;
  206.    dog.clearIntervals();
  207.    cat.clearIntervals();
  208.    pony.clearIntervals();
  209. }
  210. function finished()
  211. {
  212.    clearGame();
  213.    switch(type)
  214.    {
  215.       case "normal":
  216.          gotoAndStop("win2");
  217.          break;
  218.       case "hard":
  219.          gotoAndStop("win");
  220.          break;
  221.       default:
  222.          gotoAndStop("win1");
  223.    }
  224.    sound_MC.playing = "win";
  225. }
  226. function lost()
  227. {
  228.    clearGame();
  229.    sound_MC.playing = "lost";
  230.    gotoAndStop("lost");
  231. }
  232. function timeCount()
  233. {
  234.    time -= 1000;
  235.    if(time <= 0)
  236.    {
  237.       finished();
  238.    }
  239. }
  240. function rungame(t)
  241. {
  242.    switch(type)
  243.    {
  244.       case "normal":
  245.          happyDecreaseITV = 1500;
  246.          happyIncrement = 30;
  247.          loop = 3500;
  248.          break;
  249.       case "hard":
  250.          clearInterval(gameTunerITV);
  251.          gameTunerITV = setInterval(function()
  252.          {
  253.             self.loop -= 500;
  254.             if(self.loop <= 10)
  255.             {
  256.                self.loop = 10;
  257.                clearInterval(self.gameTunerITV);
  258.             }
  259.             self.cat.loop = self.loop;
  260.             self.dog.loop = self.loop;
  261.             self.pony.loop = self.loop;
  262.          }
  263.          ,120000);
  264.          happyDecreaseITV = 1200;
  265.          happyIncrement = 25;
  266.          loop = 2500;
  267.          break;
  268.       default:
  269.          happyDecreaseITV = 2000;
  270.          happyIncrement = 40;
  271.          loop = 5000;
  272.    }
  273.    waitTimeLoop = 50;
  274.    point = 0;
  275.    if(t > 0)
  276.    {
  277.       time = t;
  278.       gameTimerITV = setInterval(timeCount,1000);
  279.    }
  280.    else
  281.    {
  282.       time = -1;
  283.    }
  284.    if(_root.no_more_how_to_play != 1)
  285.    {
  286.       gotoAndStop("intro2");
  287.    }
  288.    else
  289.    {
  290.       gotoAndStop("game");
  291.    }
  292. }
  293. function getTime()
  294. {
  295.    return _time;
  296. }
  297. function setTime(num)
  298. {
  299.    _time = num;
  300.    if(num >= 0)
  301.    {
  302.       timeStr = "<font color=\'#" + (num <= 20 ? "ff0000" : "00ff00") + "\'>" + ("00" + int(num / 60000)).substr(-2) + ":" + ("00" + int(num / 1000) % 60).substr(-2) + "</font>";
  303.    }
  304.    else
  305.    {
  306.       timeStr = "UnLtd.";
  307.    }
  308. }
  309. _global.root = this;
  310. var index_sound;
  311. var my_so = SharedObject.getLocal("superfoo");
  312. if(my_so.data.itemNumbers == 1)
  313. {
  314.    _root.firstrun = false;
  315. }
  316. else
  317. {
  318.    _root.firstrun = true;
  319. }
  320. stop();
  321. var self = this;
  322. _global.so = SharedObject.getLocal("my_cute_pets");
  323. if(so.data.records.version != 3)
  324. {
  325.    var initHistoary = function()
  326.    {
  327.       var _loc1_ = new Array();
  328.       _loc1_.push({id:1,name:"Player",score:100000});
  329.       _loc1_.push({id:2,name:"Player",score:75000});
  330.       _loc1_.push({id:3,name:"Player",score:50000});
  331.       _loc1_.push({id:4,name:"Player",score:40000});
  332.       _loc1_.push({id:5,name:"Player",score:30000});
  333.       _loc1_.push({id:6,name:"Player",score:25000});
  334.       _loc1_.push({id:7,name:"Player",score:20000});
  335.       _loc1_.push({id:8,name:"Player",score:10000});
  336.       _loc1_.push({id:9,name:"Player",score:10000});
  337.       _loc1_.push({id:10,name:"Player",score:5000});
  338.       return _loc1_;
  339.    };
  340.    so.data.records = new Object();
  341.    so.data.records.version = 3;
  342.    so.data.records.easy = initHistoary();
  343.    so.data.records.normal = initHistoary();
  344.    so.data.records.hard = initHistoary();
  345.    so.data.records.all = initHistoary();
  346.    so.flush();
  347. }
  348. var point;
  349. var limit;
  350. var limit2;
  351. var game = new Object();
  352. game.addProperty("tool",getTool,setTool);
  353. var pointLocal = {cat:{_x:104,_y:132},dog:{_x:228,_y:132},pony:{_x:464,_y:132}};
  354. var gameTunerITV;
  355. var gameTimerITV;
  356. var type = "hard";
  357. var loop;
  358. var waitTimeLoop;
  359. var happyIncrement;
  360. var happyDecreaseITV;
  361. var timeStr;
  362. var time;
  363. var _time;
  364. addProperty("time",getTime,setTime);
  365.